<template>
  <view @click.stop="submit">
    <slot></slot>
  </view>
</template>

<script setup lang="ts">
import { payTicketGoods } from '@/api/ticketGoods'
const props = defineProps<{
  orderId: string | number
  callBack?: Function
}>()

const emit = defineEmits(['refresh'])

const submit = () => {
  uni.showLoading({
    title: '加载中'
  })
  payTicketGoods(props.orderId)
    .then((res: any) => {
      // emit('refresh')
      const response = res.data.result
      uni.requestPayment({
        provider: 'wxpay',
        appid: response.appId,
        timeStamp: response.timeStamp,
        nonceStr: response.nonceStr,
        package: response.packageStr,
        signType: response.signType,
        paySign: response.paySign,
        success: (e) => {
          uni.showToast({
            icon: 'none',
            title: '支付成功!'
          })
          // sendMessage(payList[0].price)
          if (props.callBack) {
            props.callBack(1) // 调用回调函数
          }
        },
        fail: (e) => {
          console.log('支付失败', e)
          if (props.callBack) {
            props.callBack(2) // 调用回调函数
          } else {
            // 支付异常或支付失败之后跳转到订单页面
            uni.showModal({
              content: '支付失败,如果您已支付，请勿反复支付',
              showCancel: false,
              success: () => {
                uni.redirectTo({
                  url: '/pages/ticket/ticketOrderList'
                })
              }
            })
          }
        }
      })
    })
    .finally(() => {
      emit('refresh')
    })
}

onMounted(() => {})
</script>

<style scoped lang="scss"></style>
<style>
::-webkit-scrollbar {
  width: 0px;
  height: 0px;
}
</style>
